package com.googlecode.yonggemovie.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.googlecode.yonggemovie.utils.db.BaseDao;
import com.googlecode.yonggemovie.utils.db.MultiRowMapper;

/**
 * 分类Dao, 暂不设 save, update 等功能，在数据库中初始化
 * @author root
 *
 */
public class CategoryDao extends BaseDao {
	private static CategoryDao instance=null;
	
	public static CategoryDao getInstance() {
		if (instance==null) instance=new CategoryDao();
		return instance;
	}
	
	private CategoryDao() {
		
	}
	
	/**
	 * 得到分类的列表，比如“地区”，“时间”，“获奖"
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<String> getCategoryNames() {
		String sql = "select distinct category_name from category ";
		List<String> list = this.queryForList(sql,null, new MultiRowMapper(){
			public Object mapRow(ResultSet rs) throws SQLException {			
				return rs.getString("category_name");
			}
			
		});
		
		return list;
	}
	
	/**
	 * 得到某种分类的明细分类值 ("动作片”，“故事片"）
	 * @param categoryName
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<String> getCategoryValues(String categoryName) {
		String sql = "select category_value from category where category_name = ? order by id";
		List<String> list = this.queryForList(sql,new Object[] {categoryName}, new MultiRowMapper(){
			public Object mapRow(ResultSet rs) throws SQLException {			
				return rs.getString("category_value");
			}
			
		});
		
		return list;
	}
	

}
